const express = require('express')
const app = express()
const compression = require('compression')
const path = require('path')
const port = 3001

const setLocals = require('./server/config/locals')
const injectLocals = require('./server/middlewares/injectLocals')
const beautifyHTML = require('./server/middlewares/beautifyHTML')
const indexRouter = require('./server/routes/index')

setLocals(app)

app.use(compression())

// 模板引擎 EJS
app.set('view engine', 'ejs')
app.set('views', path.join(__dirname, 'src', 'views'))
app.use(express.static('public'))

// 路由 & 路由中间件
app.use(injectLocals())
app.use(beautifyHTML())
app.use('/', indexRouter)
app.listen(port, () => {
  console.log(`网站运行在 http://localhost:${port}`)
})
